#include <bits/stdc++.h>

using namespace std;
const int maxn=110;
struct node
{
    int weight;
    vector<int> childs;
}Nodes[maxn];
int num_node,non_leafs,sum_given;
vector<int> way;
vector<vector<int>> ans;
void DFS(int index,vector<int> path,int sum)
{
    if (sum>sum_given)
    {
        return;
    }
    if (sum==sum_given)
    {
        if (Nodes[index].childs.size()!=0)
        {
            return;
        }
        ans.push_back(path);
        return;
    }
    for (int i=0;i<Nodes[index].childs.size() ;++i )
    {
        int child=Nodes[index].childs[i];
        path.push_back(Nodes[child].weight);
        DFS(child,path,sum+Nodes[child].weight);
        path.pop_back();
    }
}
int main_1053_2()
{
    scanf("%d%d%d",&num_node,&non_leafs,&sum_given);
    for (int i=0;i<num_node ;++i )
    {
        scanf("%d",&Nodes[i].weight);
    }
    int id,k,child;
    for (int i=0;i<non_leafs ;++i )
    {
        scanf("%d%d",&id,&k);
        for (int j=0;j<k ;++j )
        {
            scanf("%d",&child);
            Nodes[id].childs.push_back(child);
        }
    }
    way.push_back(Nodes[0].weight);
    DFS(0,way,Nodes[0].weight);
    sort(ans.begin(),ans.end(),greater<vector<int>>());
    for (int i=0;i<ans.size() ;++i )
    {
        printf("%d",ans[i][0]);
        for (int j=1;j<ans[i].size() ;++j )
        {
            printf(" %d",ans[i][j]);
        }
        printf("\n");
    }
    return 0;
}
